//
//  MYOriginalView.m
//  奇闻
//
//  Created by 似水灵修 on 14-11-28.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYOriginalView.h"
#import "MYStatusCellTableViewCellFrame.h"
#import "UIImageView+WebCache.h"
#import "MYStatus.h"
#import "MYUser.h"
#import "MYPhotosView.h"

@interface MYOriginalView ()
/**
 *  头像
 */
@property (nonatomic, weak) UIImageView *iconView;
/**
 *  昵称
 */
@property (nonatomic, weak) UILabel *nameView;
/**
 *  会员图片
 */
@property (nonatomic, weak) UIImageView *vipView;
/**
 *  时间
 */
@property (nonatomic, weak) UILabel *timeView;
/**
 *  来源
 */
@property (nonatomic, weak) UILabel *sourceView;
/**
 *  内容
 */
@property (nonatomic, weak) UILabel *textView;
/**
 *  配图相册
 */
@property (nonatomic ,weak) MYPhotosView *photosView;
@end
@implementation MYOriginalView
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        //添加所有子控件
        [self setupAllChildView];
        self.userInteractionEnabled = YES;
        self.image = [UIImage resizedImageWithNamed:@"timeline_card_top_background"];
    }
    return self;
}
//添加所有子控件
- (void)setupAllChildView
{
    // 头像
    UIImageView *iconView =[[UIImageView alloc] init];
    [self addSubview:iconView];
    self.iconView = iconView;
    // 昵称
    UILabel *nameView =[[UILabel alloc] init];
    nameView.font = MYNameFont;
    [self addSubview:nameView];
    self.nameView = nameView;
    nameView.textColor = [UIColor redColor];
    //会员图片
    UIImageView *vipView =[[UIImageView alloc] init];
    [self addSubview:vipView];
    self.vipView = vipView;
    // 时间
    UILabel *timeView =[[UILabel alloc] init];
    timeView.font = MYTimeFont;
    [self addSubview:timeView];
    self.timeView = timeView;
    // 来源
    UILabel *sourceView =[[UILabel alloc] init];
    sourceView.font = MYSourceFont;
    [self addSubview:sourceView];
    self.sourceView = sourceView;
    // 内容
    UILabel *textView =[[UILabel alloc] init];
    textView.font = MYTextFont;
    textView.numberOfLines = 0;
    textView.textColor = [UIColor grayColor];
    [self addSubview:textView];
    self.textView = textView;
    // 配图相册
    MYPhotosView *photosView = [[MYPhotosView alloc] init];
    [self addSubview:photosView];
    self.photosView = photosView;
    
}
//设置数据
- (void)setStatusF:(MYStatusCellTableViewCellFrame *)statusF
{
    _statusF = statusF;
    MYStatus *status = statusF.status;
    // 头像
    [self.iconView sd_setImageWithURL:status.user.profile_image_url placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];
    self.iconView.frame = statusF.iconViewF;
    
    // 昵称
    self.nameView.text = status.user.name;
    self.nameView.frame = statusF.nameViewF;
    //会员图片
    if (status.user.vip) {//会员
        NSString *imageName = [NSString stringWithFormat:@"common_icon_membership_level%d",status.user.mbrank];
        self.vipView.image = [UIImage imageNamed:imageName];
        self.vipView.hidden = NO;
        self.nameView.textColor = [UIColor redColor];
        self.vipView.frame = statusF.vipViewF;
    }
    else {
        self.vipView.hidden = YES;
        self.nameView.textColor = [UIColor blackColor];
    }
    
    //时间
    CGFloat timeX = statusF.nameViewF.origin.x;
    CGFloat timeY = CGRectGetMaxY(statusF.nameViewF);
    CGSize timeSzie = [statusF.status.created_at sizeWithFont:MYTimeFont];
    self.timeView.frame = (CGRect){{timeX, timeY}, timeSzie};
    self.timeView.text = status.created_at;
    //来源
    CGFloat sourceX = CGRectGetMaxX(self.timeView.frame) + MYCellMargin;
    CGFloat sourceY = timeY;
    CGSize sourceSize = [statusF.status.source sizeWithFont:MYSourceFont];
    self.sourceView.frame = (CGRect){{sourceX,sourceY},sourceSize};
    self.sourceView.text = status.source;
    // 内容
    self.textView.text = status.text;
    self.textView.frame = statusF.textViewF;
    // 配图相册
    self.photosView.pic_urls = status.pic_urls;
    self.photosView.frame = statusF.photosViewF;
}
@end
